package com.zweicom.bconsumo.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zweicom.bconsumo.model.Perfil;
import com.zweicom.bconsumo.dao.PerfilDAO;

/**
 * Handles and retrieves perfil requests.
 */
@Controller
public class PerfilController {
	
	@Autowired
	private PerfilDAO oPerfilDAO;
		
		private static final Logger logger = LoggerFactory.getLogger(PerfilController.class);
		
		/**
		  * Handles and retrieves all perfiles and show it in a JSP page
		  *
		  * @return the name of the JSP page
		  */
		@RequestMapping(value="/perfil")
		public String listPerfiles(Model oModel) {
			
			logger.info("Received request to show all persons");
			
			// Retrieve all perfiles by delegating the call to oPerfilDAO
			List<Perfil> lPerfiles = oPerfilDAO.getAll();
			
			// Attach persons to the Model
			oModel.addAttribute("perfiles", lPerfiles);
			
			// This will resolve to /WEB-INF/views/dsp_perfiles.jsp
			return "showPerfiles";
		
		}

}
